package com.dries.portal.browser.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

/**
 * @Description:
 * @Author ZSY
 * @createTime 2020/9/2 16:29
 */
@Slf4j
@Aspect
@Component
public class WebAspect {

    @Around("execution(public * com.dries.portal.browser.controller.*.*(..))")
    public Object handleControllerMethod(ProceedingJoinPoint pjp) {

        // 请求开始时间
        long startTime = System.currentTimeMillis();
        System.out.println("web aspect start");

        Object[] args = pjp.getArgs();

        for (Object arg : args) {
            System.out.println("arg is " + arg);
        }

        Object proceed = null;
        try {
            proceed = pjp.proceed();
            // 请求结束时间
            long endTime = System.currentTimeMillis();
            System.out.println("web aspect end");
            System.out.println("web aspect 耗时：" + Math.toIntExact(endTime - startTime) + "s");
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
        return proceed;
    }

}
